<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>distance</title>
</head>
<body>
   <canvas id="canvas" width="500" height="500" style="background:#000;">
       your browser not support canvas!
   </canvas>
   <textarea name="" id="log" cols="30" rows="10"></textarea>
   <script src="../js/utils.js"></script>
   <script src="../js/ball.js"></script>
   <script>
       window.onload = function(){
           var canvas = document.getElementById('canvas'),
               context = canvas.getContext('2d'),
               mouse = utils.captureMouse(canvas),
               ball_1 = new Ball(20, "#49f"),
               ball_2 = new Ball(20, "#f00");
           
       
           
           ball_2.x = canvas.width/2;
           ball_2.y = canvas.height/2;
           
          
           ball_1.draw(context);
           ball_2.draw(context);
           
           canvas.addEventListener('mousemove',function(e){
               context.clearRect(0, 0, canvas.width, canvas.height);
               ball_1.x = mouse.x;
               ball_1.y = mouse.y;
               var dx = ball_2.x - ball_1.x;
               var dy = ball_2.y - ball_1.y;
               var dist = Math.sqrt(dx*dx + dy*dy);
               if(dist < 100){
                   log.innerHTML = '碰着了';
               }else{
                   log.innerHTML = "";
               }
               ball_1.draw(context);
               ball_2.draw(context);
           },false);
       }
    </script>
    
</body>
</html>